- title 'Users'
- content_for :head do
  = javascript_include_tag 'sections/users'
- content_for :title do
  = link_to "← Back to account dashboard", account_path(current_account), :class => 'back'

- if @users.blank?
  - content_for :title do
    %h1 No users have access
- else
  - content_for :title do
    %h1 Account users
  %h2.divider Users with access to this account
  %form
    %table.users
      %tr
        %th Name
        %th Email address
        %th Permission
        %th Account Administrator
      - @users.each do |user_id, account_user|
        - select_id = "user-privilege-#{user_id}"
        %tr
          %td
            = label_tag select_id, account_user.user.name
          %td
            = label_tag select_id, account_user.user.email
          - if account_user.user == current_user
            %td
              .admin-access Administrator access to all features
            %td.admin
              %b{ :title => 'You cannot turn off your own admin rights', :class => 'vtip' } Yes
          - else
            %td.privilege
              %select.privilege{ :id => select_id, :name => select_id }
                = raw privilege_options account_user
            %td.admin
              = check_box_tag "user-#{user_id}", 1, account_user.admin?, :title => 'Account administrators can manage this account, invite new users and view and edit all backlogs', :class => 'admin vtip'
            %td.action
              = link_to account_user_path(current_account, account_user.user), :method => 'delete', :title => 'Remove user?', :confirm => 'Are you sure you want to remove this user from your account?' do
                %span.ui-icon.ui-icon-trash
            %td.action
              .progress-icon
  - unless @invites.empty?
    %br/
    %h2.divider Invites not yet redeemed
    %p
      The following people have been invited to join but not yet signed up to easyBacklog.
      %table.invites
        - @invites.each do |invite|
          %tr
            %td.email
              = invite.email
            %td.action
              .delete-container
                = link_to account_invite_path(current_account, invite), :method => 'delete', :title => 'Revoke invite?', :confirm => 'Are you sure you want to revoke this invite?' do
                  %span.ui-icon.ui-icon-trash
              .resend-container
                = link_to 'resend invite', resend_account_invite_path(current_account, invite), :method => 'post'
  = link_to 'Invite new users', new_account_user_path(current_account), :class => 'button'
  = link_to 'cancel', account_path(current_account)
